// const { data } = require("jquery")
template.defaults.imports.dateFormat = function (dtStr) {
  let date = new Date(dtStr)
  let y = date.getFullYear()
  let m = date.getMonth() + 1
  let d = date.getDate()
  let h = date.getHours()
  let mm = date.getMinutes()
  let s = date.getSeconds()
  return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s
}

$.ajax({
  url: 'http://localhost:8888/api/articles',
  data: {
    pagenum: 1,
    pagesize: 6
  },
  success: function (res) {
    // console.log(11)
    let temp = template('tpl-list-first', res)
    $('.kr_news_list:nth-child(1)').append(temp)
  }
})

let i = 1

$('.kr_more a').on('click', function () {
  // console.log(11)
  if (i === 1) {
    $.ajax({
      url: 'http://localhost:8888/api/articles',
      data: {
        pagenum: 2,
        pagesize: 6
      },
      success: function (res) {
        console.log(res)
        // console.log(11)
        let temp = template('tpl-list-first', res)
        $('#last-list').append(temp)
      }
    })
    
    i++
  } else if (i === 2) {
    $.ajax({
      url: 'http://localhost:8888/api/articles',
      data: {
        pagenum: 3,
        pagesize: 6
      },
      success: function (res) {
        console.log(res)
        // console.log(11)
        let temp = template('tpl-list-first', res)
        $('#last-list').append(temp)
        $('.kr_more a').html('加载完毕')
        
      }
    })
    i++
  } else{
    layer.msg('没有更多数据了')
  }

})

$.ajax({
  url:'http://localhost:8888/api/links',
  success:function(res) {

    let temp = template('tpl-link', res)
    $('.kr_collaborator').append(temp)
  }
})